package cn.ixiaoxin.deepchat.util;

import lombok.Data;

@Data
public class Result<T> {
    private int code;
    private String msg;
    private T data;

    protected Result () {}

    protected Result(int code,String msg,T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> Result<T> success(String msg,T data) {
        return new Result(200,msg,data);
    }

    public static <T> Result<T> error(String msg,T data) {
        return new Result(500,msg,data);
    }

    public static <T> Result<T> success(String msg) {
        return success(msg,null);
    }

    public static <T> Result<T> success(T data) {
        return success("成功",data);
    }

    public static <T> Result<T> success() {
        return success("成功",null);
    }

    public static <T> Result<T> error(String msg) {
        return error(msg,null);
    }

    public static <T> Result<T> error(T data) {
        return error("失败",data);
    }

    public static <T> Result<T> error() {
        return error("失败",null);
    }

}
